import React, {Component} from 'react';
// Home 为路由组件
import Home from "./pages/Home/Home";
import About from "./pages/About/About";
import {Redirect, Route, Switch} from "react-router-dom";
// Header 是一般组件
import Header from "./components/Header/Header";
import MyNavLink from "./components/MyNavLink/MyNavLink";

class RouterOne extends Component {
    render() {
        return (
            <div>
                <div className="row">
                    <div className="col-xs-offset-2 col-xs-8">
                        <Header/>
                    </div>
                </div>
                <div className="row">
                    <div className="col-xs-2 col-xs-offset-2">
                        <div className="list-group">
                            {/*在React中靠路由链接实现组件却换--编写路由链接*/}
                            <MyNavLink to="/about">About</MyNavLink>
                            <MyNavLink to="/home">Home</MyNavLink>
                        </div>
                    </div>
                    <div className="col-xs-6">
                        <div className="panel">
                            <div className="panel-body">
                                {/*注册路由 Switch 单一匹配（默认情况路由匹配到一个路径还是继续向下匹配）*/}
                                <Switch>
                                    {/*默认是模糊匹配 exact={true} 开启精准匹配*/}
                                    <Route path="/home" component={Home}/>
                                    <Route exact={true} path="/about" component={About}/>
                                    {/*Redirect 重定向，用于初始指定去到哪路由*/}
                                    <Redirect to="/About"/>
                                </Switch>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}

export default RouterOne;